package com.wuxin.ssm.service.impl;


import com.wuxin.ssm.entity.Admin;
import com.wuxin.ssm.entity.AdminExample;
import com.wuxin.ssm.mapper.AdminMapper;
import com.wuxin.ssm.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: untitled
 * @ClassName AdminServiceImpl
 * @description:
 * @author: 李尧坤
 * @create: 2024−12-02 17:05
 * @Version 1.0
 **/

@Service
public class AdminServiceImpl  implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public String login(String name, String pwd) {
        String flag="no";
        //我们使用帮助类 Example
        AdminExample example = new AdminExample();
        //需要将用户名传入 作为查询条件
        example.createCriteria().andANameEqualTo(name);

        //获取到的是集合
        List<Admin> adminList = adminMapper.selectByExample(example);

        if(adminList!=null && adminList.size()>0){
            //获取数据
            Admin admin = adminList.get(0);
            //检验密码是否合法
            if(pwd.equals(admin.getaPass())){
                //传入的密码  和数据库的密码 相等 【目前我们的密码是明文的 非加密的 】
                flag="ok";
            }
        }
        return flag;
    }







/*    @Override
    public boolean doLogin(String name, String pwd) {
        //获取用户
        Admin  adminFrom =  new Admin();
        adminFrom.setaName(name);
        adminFrom.setaPass(pwd);

        //admin  是数据库的对象
        Admin admin = adminMapper.findUserByCondition(adminFrom);

        if (admin != null) {
            //有数据
            return true;
        }

        return false;
    }*/
}
